import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

class EasyFreshPage extends StatefulWidget {
  @override
  _EasyFreshPageState createState() => _EasyFreshPageState();
}

class _EasyFreshPageState extends State<EasyFreshPage> {
  List<String> listData = [];

  @override
  void initState() {
    _loadData();
    super.initState();
  }

  void _loadData() {
    for (int i = 1; i < 20; i++) {
      listData.add('第 $i 个数据');
    }
  }

  List<Widget> _getData() {
    List<Widget> listWidget = [];
    for (int i = 0; i < listData.length; i++) {
      listWidget.add(Text(listData[i]));
    }
    return listWidget;
  }
  Widget _item(int index) {
    return Text(listData[index]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('easyFresh学习'),
        ),
        body: Container(
            color: Colors.red,
            padding: EdgeInsets.all(10),
            child: EasyRefresh(
               child:ListView.builder(
                itemBuilder: (_, index) => _item(index),
                itemCount: listData.length,
              ),
              onRefresh: () async {
                 await Future.delayed(Duration(seconds: 2),(){
                   listData.add('头刷新1');
                   setState(() {});
                 });

              },
              onLoad: () async{
                await Future.delayed(Duration(seconds: 2),(){
                  listData.add('尾刷新--${listData.length}');
                  setState(() {});
                });
              },
            )));
  }


}
